﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace 深入浅出WPF_Chapter7依赖属性
{
    /// <summary>
    /// Sample2.xaml 的交互逻辑
    /// </summary>
    public partial class Sample2 : Window
    {
        Student stu;
        public Sample2()
        {
            InitializeComponent();

            stu = new Student();
            Binding binding = new Binding("Text") { Source = textBox1 };
            BindingOperations.SetBinding(stu,Student.NameProperty, binding);
            //textBox2.SetBinding(TextBox.TextProperty,binding);

            ////以下绑定未生效
            //Binding binding1 = new Binding("NameProperty") { Source = stu };
            //textBox2.SetBinding(TextBox.TextProperty, binding1);

            Binding binding1 = new Binding("Name") { Source = stu };
            textBox2.SetBinding(TextBox.TextProperty, binding1);
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            //MessageBox.Show(stu.GetValue(Student.NameProperty).ToString());
            MessageBox.Show(stu.Name);
        }
    }
}
